//
//  UserService.m
//  AILock
//
//  Created by 谭亚明 on 2020/6/23.
//  Copyright © 2020 tym. All rights reserved.
//

#import "UserService.h"
#import "YYModel.h"
#import <JPUSHService.h>
#import "LMJBaseResponse.h"
#import "DeviceInfo.h"
@implementation UserService

-(void)getLoginWithMobile:(NSString*)mobile password:(NSString*)password completion:(void(^)(LMJBaseResponse *respon, UserModel *user))completiont{
    
    NSDictionary *dic = @{@"username":mobile,
                                                @"password":password,
                                                @"meId":[DeviceInfo keyChainUUID],
                                                @"type":@"username",
                                               @"identity":@"1",
                                                @"channel":@"2",
                                                @"registerWay":@"0",
                                                @"appVersion":[DeviceInfo getLocalAppVersion],
                                                @"termModel":[DeviceInfo getPlatformString],
                                                @"termSystemVersion":@"",
                                                @"termId":@"",
                                                @"macAddress":[DeviceInfo getMacAddress],
                          @"jgregId":[JPUSHService registrationID]?[JPUSHService registrationID]:@"888"};
    
    [self POST:urlLogin  parameters:dic completion:^(LMJBaseResponse *response) {
        completiont(response,[UserModel yy_modelWithJSON:response.responseObject[@"data"]]);
    }];
}

-(void)getUpdatePassword:(NSString*)userName validateionCode:(NSString*)code newPassword:(NSString*)password completion:(void(^)(NSError *error, LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"username":userName,
                          @"validationCode":code,
                          @"newPassword":password
    };
    [self POST:urlPasswordupdate parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response.error,response);
    }];
}

-(void)getResiterMobile:(NSString*)mobile password:(NSString*)password channel:(NSString*)channel regiterWay:(NSString*)registerWay validateionCode:(NSString*)code completion:(void(^)(NSError *error, LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"mobile":mobile,
                          @"password":password,
                          @"channel":channel,
                          @"registerWay":registerWay,
                          @"validationCode":code};
    [self POST:urlRegister parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response.error,response);
    }];
}

-(void)getValidteionCode:(NSString*)mobile completion:(void(^)(NSError *error, LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"mobile":mobile};
    [self GET:urlValidationcode parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response.error,response);
    }];
}

-(void)getUpdatepwd:(NSString*)password newPassword:(NSString*)newPassword completion:(void(^)(NSError *error, LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"password":password,
                          @"newPassword":newPassword};
    [self POST:urlUpdatepwd parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response.error,response);
    }];
}

-(void)getVerificationCode:(NSString*)mobile  validateionCode:(NSString*)validateionCode completion:(void(^)(NSError *error, LMJBaseResponse *response))completion{
    NSDictionary *dic = @{@"mobileNumber":mobile,
                             @"validationCode":validateionCode};
       [self POST:urlVerificationcode parameters:dic completion:^(LMJBaseResponse *response) {
           completion(response.error,response);
       }];
}

-(void)getUpdateUser:(NSString*)realName sex:(NSInteger)sex nickName:(NSString*)nickName headImagUrl:(NSString*)headImage completion:(void(^)(NSError *error, LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"realName":realName?realName:@"",
                          @"sex":@(sex),
                          @"nickname":nickName,
                          @"headImgUrl":headImage?headImage:@""};
    [self POST:urlUpdateuser parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response.error,response);
        
    }];
}

-(void)getUpdateUserMobile:(NSString*)mobile validateionCode:(NSString*)code completion:(void(^)(NSError *error, LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"mobile":mobile,
                          @"validationCode":code};
    [self POST:urlUpdateusermobil parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response.error,response);
    }];
}

-(void)getLogoutcompletion:(void(^)(NSError *error, LMJBaseResponse *response))completion{
    
    [self POST:urlLogout parameters:nil completion:^(LMJBaseResponse *response) {
        completion(response.error,response);
    }];
}

-(void)getFinduser:(NSString*)mobile  completion:(void(^)(NSError *error, UserModel  *user))completion{
    
    NSDictionary *dic = @{@"mobile":mobile};
    [self GET:urlFinduser parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response.error,[UserModel yy_modelWithJSON:response.responseObject[@"data"]]);
    }];
}

-(void)getFindusercompletion:(void(^)(NSError *error, UserModel *response))completion{
    [self GET:urlGetuser parameters:nil completion:^(LMJBaseResponse *response) {
        completion(response.error,[UserModel yy_modelWithJSON:response.responseObject[@"data"]]);
    }];
}

/*无参获取用户*/
-(void)getFindnewversion:(void(^)(LMJBaseResponse *error, VersionModel *response))completion{
    
    NSDictionary *dic = @{@"systemType":@(3)};
    [self GET:urlFindnewversion parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response,[VersionModel yy_modelWithJSON:response.responseObject[@"data"]]);
    }];
}

-(void)getUpdateyoukeUserUserId:(NSInteger)userId familyId:(NSInteger)familyId
nickname:(NSString*)nickname
headImgUrl:(NSString*)headImgUrl
                     completion:(void(^)(LMJBaseResponse *response))completion{
    
    NSDictionary *dic = @{@"userId":@(userId),
                          @"familyId":@(familyId),
                          @"nickname":nickname,
                          @"headImgUrl":headImgUrl
    };
    [self POST:urlUpdateequipmentgroupuser  parameters:dic completion:^(LMJBaseResponse *response) {
        completion(response);
    }];
    
    
    
}
@end
